/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.google.common.collect.Maps;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Cos;
/*     */ import com.zimbra.cs.account.DistributionList;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Group;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Provisioning.GroupMembership;
/*     */ import com.zimbra.cs.account.accesscontrol.Right;
/*     */ import com.zimbra.cs.account.accesscontrol.RightManager;
/*     */ import com.zimbra.cs.account.ldap.LdapProvisioning;
/*     */ import com.zimbra.cs.account.soap.SoapProvisioning;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ public class TestCustomDynamicGroupCache extends junit.framework.TestCase
/*     */ {
/*     */   final String domainName = "cdgcache.test";
/*     */   final String domainName1 = "cdgcache1.test";
/*     */   final String domainName2 = "cdgcache2.test";
/*     */   final String acctPatt = "person%03d@cdgcache.test";
/*     */   final String normalDLPatt = "normaldl%03d@cdgcache.test";
/*     */   final String dynamicDLPatt = "dynamicdl%03d@cdgcache.test";
/*     */   final String customDLPatt = "cosdl%03d@cdgcache.test";
/*     */   final String cosPatt = "cdgcachecos%03d";
/*     */   final int NUM_ACCOUNTS_SMALL = 8;
/*     */   final int NUM_NORMAL_DL_SMALL = 8;
/*     */   final int NUM_DYNAMIC_DL_SMALL = 8;
/*     */   final int NUM_ACCOUNTS_PERF = 40;
/*     */   final int NUM_NORMAL_DL_PERF = 1000;
/*     */   final int NUM_DYNAMIC_DL_PERF = 200;
/*     */   final int NUM_ACCOUNTS = 8;
/*     */   final int NUM_NORMAL_DL = 8;
/*     */   final int NUM_DYNAMIC_DL = 8;
/*     */   final int NUM_COS = 4;
/*     */   final int NUM_CUSTOM_DL = 4;
/*     */   private Domain domain;
/*     */   private Domain domain1;
/*     */   private Domain domain2;
/*     */   private SoapProvisioning soapProv;
/*     */   private LdapProvisioning ldapProv;
/*     */   private final Map<String, Group> groups;
/*     */   
/*     */   public TestCustomDynamicGroupCache()
/*     */   {
/*  51 */     this.domainName = "cdgcache.test";
/*  52 */     this.domainName1 = "cdgcache1.test";
/*  53 */     this.domainName2 = "cdgcache2.test";
/*  54 */     this.acctPatt = "person%03d@cdgcache.test";
/*  55 */     this.normalDLPatt = "normaldl%03d@cdgcache.test";
/*  56 */     this.dynamicDLPatt = "dynamicdl%03d@cdgcache.test";
/*  57 */     this.customDLPatt = "cosdl%03d@cdgcache.test";
/*  58 */     this.cosPatt = "cdgcachecos%03d";
/*     */     
/*  60 */     this.NUM_ACCOUNTS_SMALL = 8;
/*  61 */     this.NUM_NORMAL_DL_SMALL = 8;
/*  62 */     this.NUM_DYNAMIC_DL_SMALL = 8;
/*     */     
/*  64 */     this.NUM_ACCOUNTS_PERF = 40;
/*  65 */     this.NUM_NORMAL_DL_PERF = 1000;
/*  66 */     this.NUM_DYNAMIC_DL_PERF = 200;
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*  71 */     this.NUM_ACCOUNTS = 8;
/*  72 */     this.NUM_NORMAL_DL = 8;
/*  73 */     this.NUM_DYNAMIC_DL = 8;
/*     */     
/*  75 */     this.NUM_COS = 4;
/*  76 */     this.NUM_CUSTOM_DL = 4;
/*     */     
/*  78 */     this.domain = null;
/*  79 */     this.domain1 = null;
/*  80 */     this.domain2 = null;
/*  81 */     this.soapProv = null;
/*  82 */     this.ldapProv = null;
/*  83 */     this.groups = Maps.newHashMap();
/*     */   }
/*     */   
/*     */   private class GetMembershipClientThread implements Runnable
/*     */   {
/*     */     private final Account acct;
/*     */     private final LdapProvisioning prov;
/*     */     private final Set<Right> urights;
/*     */     
/*     */     private GetMembershipClientThread(Account p, Set<Right> account) {
/*  93 */       this.prov = p;
/*  94 */       this.acct = account;
/*  95 */       this.urights = rights;
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */     public void run()
/*     */     {
/*     */       try
/*     */       {
/* 104 */         for (int cnt = 0; cnt < 20; cnt++)
/*     */         {
/* 106 */           long before = System.currentTimeMillis();
/* 107 */           Provisioning.GroupMembership membership = this.prov.getGroupMembership(this.acct, false);
/* 108 */           long after = System.currentTimeMillis();
/* 109 */           ZimbraLog.test.info("XXX getGroupMembership ms=%s acct=%s NUM=%s", new Object[] { Long.valueOf(after - before), this.acct.getName(), Integer.valueOf(membership.groupIds().size()) });
/*     */           
/* 111 */           before = System.currentTimeMillis();
/* 112 */           membership = this.prov.getGroupMembershipWithRights(this.acct, this.urights, false);
/* 113 */           after = System.currentTimeMillis();
/* 114 */           ZimbraLog.test.info("XXX getGroupMembershipWithRights ms=%s acct=%s NUM=%s", new Object[] { Long.valueOf(after - before), this.acct.getName(), Integer.valueOf(membership.groupIds().size()) });
/*     */         }
/*     */       }
/*     */       catch (Exception e) {
/* 118 */         ZimbraLog.test.error("Unable to get membership for %s.", this.acct, e);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */   public void ENABLE_FOR_PERFORMANCE_TESTStestCustomDynamicGroups()
/*     */     throws Exception
/*     */   {
/* 127 */     RightManager rightMgr = RightManager.getInstance();
/* 128 */     Set<Right> rights = com.google.common.collect.Sets.newHashSet();
/* 129 */     rights.add(rightMgr.getUserRight("createDistList"));
/* 130 */     Thread[] threads = new Thread[80];
/* 131 */     for (int i = 0; i < threads.length; i++) {
/* 132 */       String acctName = String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(i % 10 + 1) });
/* 133 */       Account acct = this.soapProv.getAccountByName(acctName);
/* 134 */       threads[i] = new Thread(new GetMembershipClientThread(this.ldapProv, acct, rights, null));
/*     */     }
/* 136 */     for (Thread thread : threads) {
/* 137 */       thread.start();
/*     */     }
/* 139 */     for (Thread thread : threads) {
/* 140 */       thread.join();
/*     */     }
/*     */   }
/*     */   
/*     */   private Provisioning.GroupMembership doGetGroupMembershipWithRights(Account acct, Set<Right> rights, int expected, int adminOnlyExpected) throws com.zimbra.common.service.ServiceException
/*     */   {
/*     */     String rightsDesc;
/*     */     String rightsDesc;
/* 148 */     if (rights == null) {
/* 149 */       rightsDesc = "rights={ALL(null)}"; } else { String rightsDesc;
/* 150 */       if (rights.isEmpty()) {
/* 151 */         rightsDesc = "rights={ALL(empty)}";
/*     */       } else {
/* 153 */         StringBuilder sb = new StringBuilder("rights=");
/* 154 */         for (Right right : rights) {
/* 155 */           if (sb.length() > 7) {
/* 156 */             sb.append(',');
/*     */           }
/* 158 */           sb.append(right.getName());
/*     */         }
/* 160 */         rightsDesc = sb.toString();
/*     */       } }
/* 162 */     long before = System.currentTimeMillis();
/* 163 */     Provisioning.GroupMembership membership = this.ldapProv.getGroupMembershipWithRights(acct, rights, false);
/* 164 */     long after = System.currentTimeMillis();
/* 165 */     String groupNames = groupInfo(membership.groupIds());
/* 166 */     ZimbraLog.test.info("YYY getGroupMembershipWithRights %s ms=%s acct=%s size=%s\n%s\ngroupNames=%s", new Object[] { rightsDesc, Long.valueOf(after - before), acct.getName(), Integer.valueOf(membership.groupIds().size()), membership, groupNames });
/*     */     
/*     */ 
/* 169 */     before = System.currentTimeMillis();
/* 170 */     Provisioning.GroupMembership adminOnlyMembership = this.ldapProv.getGroupMembershipWithRights(acct, rights, true);
/* 171 */     after = System.currentTimeMillis();
/* 172 */     String adminOnlyGroupNames = groupInfo(membership.groupIds());
/* 173 */     ZimbraLog.test.info("YYY getGroupMembershipWithRights [adminOnly] %s ms=%s acct=%s size=%s\n%s\ngroupNames=%s", new Object[] { rightsDesc, Long.valueOf(after - before), acct.getName(), Integer.valueOf(adminOnlyMembership.groupIds().size()), adminOnlyMembership, adminOnlyGroupNames });
/*     */     
/*     */ 
/*     */ 
/* 177 */     assertEquals(String.format("Number of groups with %s which contain %s groups=%s", new Object[] { rightsDesc, acct.getName(), groupNames }), expected, membership.groupIds().size());
/*     */     
/*     */ 
/* 180 */     assertEquals(String.format("Number of adminOnly groups with %s which contain %s groups=%s", new Object[] { rightsDesc, acct.getName(), adminOnlyGroupNames }), adminOnlyExpected, adminOnlyMembership.groupIds().size());
/*     */     
/*     */ 
/* 183 */     return membership;
/*     */   }
/*     */   
/*     */   private String groupInfo(Iterable<String> groupIDs) {
/* 187 */     StringBuilder sb = new StringBuilder();
/* 188 */     for (String groupID : groupIDs) {
/* 189 */       if (sb.length() > 0) {
/* 190 */         sb.append(',');
/*     */       }
/* 192 */       Group grp = (Group)this.groups.get(groupID);
/* 193 */       if (grp == null) {
/* 194 */         sb.append("UNKOWN-").append(groupID);
/*     */       } else {
/* 196 */         sb.append(grp.getName()).append("(id=").append(groupID).append(")");
/*     */       }
/*     */     }
/* 199 */     return sb.toString();
/*     */   }
/*     */   
/*     */   private void doAnyRightsTestForAccount(String acctName, int expected, int adminOnlyExpected) throws com.zimbra.common.service.ServiceException
/*     */   {
/* 204 */     Set<Right> rights = com.google.common.collect.Sets.newHashSet();
/*     */     
/* 206 */     Account acct = this.soapProv.getAccountByName(acctName);
/* 207 */     doGetGroupMembershipWithRights(acct, rights, expected, adminOnlyExpected);
/* 208 */     doGetGroupMembershipWithRights(acct, null, expected, adminOnlyExpected);
/*     */   }
/*     */   
/*     */   private void doRightsTestForAccount(String acctName, int expected, int adminOnlyExpected) throws com.zimbra.common.service.ServiceException {
/* 212 */     RightManager rightMgr = RightManager.getInstance();
/* 213 */     Set<Right> rights = com.google.common.collect.Sets.newHashSet();
/* 214 */     rights.add(rightMgr.getUserRight("createDistList"));
/*     */     
/* 216 */     Account acct = this.soapProv.getAccountByName(acctName);
/* 217 */     doGetGroupMembershipWithRights(acct, rights, expected, adminOnlyExpected);
/*     */   }
/*     */   
/*     */   public void testCustomDynamicGroupsAnyRights1() throws Exception
/*     */   {
/* 222 */     doAnyRightsTestForAccount(String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(1) }), 0, 0);
/*     */   }
/*     */   
/*     */   public void testCustomDynamicGroupsCreateDistListRights1() throws Exception {
/* 226 */     doRightsTestForAccount(String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(1) }), 0, 0);
/*     */   }
/*     */   
/*     */   public void testCustomDynamicGroupsAnyRights2()
/*     */     throws Exception
/*     */   {
/* 232 */     doAnyRightsTestForAccount(String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(2) }), 1, 0);
/*     */   }
/*     */   
/*     */   public void testCustomDynamicGroupsCreateDistListRights2() throws Exception {
/* 236 */     doRightsTestForAccount(String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(2) }), 1, 0);
/*     */   }
/*     */   
/*     */ 
/*     */   public void testCustomDynamicGroupsAnyRights3()
/*     */     throws Exception
/*     */   {
/* 243 */     doAnyRightsTestForAccount(String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(3) }), 2, 0);
/*     */   }
/*     */   
/*     */   public void testCustomDynamicGroupsCreateDistListRights3() throws Exception {
/* 247 */     doRightsTestForAccount(String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(3) }), 1, 0);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public void testCustomDynamicGroupsAnyRights4()
/*     */     throws Exception
/*     */   {
/* 255 */     doAnyRightsTestForAccount(String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(4) }), 2, 0);
/*     */   }
/*     */   
/*     */   public void testCustomDynamicGroupsCreateDistListRights4() throws Exception {
/* 259 */     doRightsTestForAccount(String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(4) }), 2, 0);
/*     */   }
/*     */   
/*     */   private void doGetCustomDynamicGroupMembership(int acctNum) throws com.zimbra.common.service.ServiceException
/*     */   {
/* 264 */     String acctName = String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(acctNum) });
/* 265 */     Account acct = this.ldapProv.getAccountByName(acctName);
/* 266 */     Provisioning.GroupMembership membership = this.ldapProv.getCustomDynamicGroupMembership(acct, false);
/* 267 */     String groupNames = groupInfo(membership.groupIds());
/* 268 */     assertEquals(String.format("Number of dynamic groups with custom memberURL s which contain %s groups=%s", new Object[] { acct.getName(), groupNames }), 1, membership.groupIds().size());
/*     */     
/* 270 */     String cosName = String.format("cosdl%03d@cdgcache.test", new Object[] { Integer.valueOf(acctNum % 4 + 1) });
/* 271 */     Group grp = (Group)this.groups.get(membership.groupIds().get(0));
/* 272 */     String groupName = grp == null ? "UNKNOWN" : grp.getName();
/* 273 */     assertEquals(String.format("Name of dynamic group with custom memberURL s which contains %s", new Object[] { acctName }), cosName, groupName);
/*     */   }
/*     */   
/*     */   public void testGetCustomDynamicGroups() throws Exception
/*     */   {
/* 278 */     doGetCustomDynamicGroupMembership(1);
/* 279 */     doGetCustomDynamicGroupMembership(4);
/*     */   }
/*     */   
/*     */   public void testInACLGRoup() throws Exception
/*     */   {
/* 284 */     String acctName = String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(1) });
/* 285 */     doInACLGroup(acctName, String.format("normaldl%03d@cdgcache.test", new Object[] { Integer.valueOf(1) }), false);
/* 286 */     doInACLGroup(acctName, String.format("dynamicdl%03d@cdgcache.test", new Object[] { Integer.valueOf(1) }), false);
/* 287 */     doInACLGroup(acctName, String.format("cosdl%03d@cdgcache.test", new Object[] { Integer.valueOf(1) }), false);
/* 288 */     acctName = String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(2) });
/* 289 */     doInACLGroup(acctName, String.format("normaldl%03d@cdgcache.test", new Object[] { Integer.valueOf(1) }), true);
/* 290 */     doInACLGroup(acctName, String.format("dynamicdl%03d@cdgcache.test", new Object[] { Integer.valueOf(1) }), false);
/* 291 */     doInACLGroup(acctName, String.format("cosdl%03d@cdgcache.test", new Object[] { Integer.valueOf(1) }), false);
/* 292 */     acctName = String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(3) });
/* 293 */     doInACLGroup(acctName, String.format("normaldl%03d@cdgcache.test", new Object[] { Integer.valueOf(1) }), false);
/* 294 */     doInACLGroup(acctName, String.format("dynamicdl%03d@cdgcache.test", new Object[] { Integer.valueOf(1) }), true);
/* 295 */     doInACLGroup(acctName, String.format("cosdl%03d@cdgcache.test", new Object[] { Integer.valueOf(1) }), false);
/* 296 */     acctName = String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(4) });
/* 297 */     doInACLGroup(acctName, String.format("normaldl%03d@cdgcache.test", new Object[] { Integer.valueOf(1) }), true);
/* 298 */     doInACLGroup(acctName, String.format("dynamicdl%03d@cdgcache.test", new Object[] { Integer.valueOf(1) }), false);
/* 299 */     doInACLGroup(acctName, String.format("cosdl%03d@cdgcache.test", new Object[] { Integer.valueOf(1) }), true);
/*     */   }
/*     */   
/*     */   private void doInACLGroup(String acctName, String groupName, boolean expected) throws com.zimbra.common.service.ServiceException {
/* 303 */     Account acct = this.ldapProv.getAccountByName(acctName);
/* 304 */     Group group = this.ldapProv.getGroup(com.zimbra.common.account.Key.DistributionListBy.name, groupName);
/* 305 */     assertEquals(String.format("account %s in group %s", new Object[] { acct.getName(), group.getName() }), expected, this.ldapProv.inACLGroup(acct, group.getId()));
/*     */   }
/*     */   
/*     */   public void setUp()
/*     */     throws Exception
/*     */   {
/* 311 */     this.ldapProv = ((LdapProvisioning)Provisioning.getInstance());
/* 312 */     if (this.soapProv == null) {
/* 313 */       this.soapProv = TestUtil.newSoapProvisioning();
/*     */     }
/* 315 */     tearDown();
/* 316 */     this.domain = createDomain("cdgcache.test");
/* 317 */     this.domain1 = createDomain("cdgcache1.test");
/* 318 */     this.domain2 = createDomain("cdgcache2.test");
/* 319 */     for (int cnt = 1; cnt <= 4; cnt++) {
/* 320 */       createCos(String.format("cdgcachecos%03d", new Object[] { Integer.valueOf(cnt) }));
/*     */     }
/* 322 */     this.groups.clear();
/* 323 */     for (int cnt = 1; cnt <= 4; cnt++) {
/* 324 */       TestUtil.deleteAccount(String.format("cosdl%03d@cdgcache.test", new Object[] { Integer.valueOf(cnt) }));
/* 325 */       Group grp = createCustomDynamicGroupWhoseMembersShareCOS(String.format("cosdl%03d@cdgcache.test", new Object[] { Integer.valueOf(cnt) }), String.format("cdgcachecos%03d", new Object[] { Integer.valueOf(cnt) }));
/* 326 */       this.groups.put(grp.getId(), grp);
/*     */     }
/* 328 */     List<String> staticMembers = com.google.common.collect.Lists.newArrayList();
/* 329 */     List<String> dynamicMembers = com.google.common.collect.Lists.newArrayList();
/* 330 */     for (int cnt = 1; cnt <= 8; cnt++) {
/* 331 */       int cosChoice = cnt % 4 + 1;
/* 332 */       createAccountAsMemberOfCOS(String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(cnt) }), String.format("cdgcachecos%03d", new Object[] { Integer.valueOf(cosChoice) }));
/* 333 */       if (cnt % 2 == 0) {
/* 334 */         staticMembers.add(String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(cnt) }));
/*     */       }
/* 336 */       if (cnt % 3 == 0)
/* 337 */         dynamicMembers.add(String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(cnt) }));
/*     */     }
/*     */     DistributionList dl;
/* 340 */     for (int cnt = 1; cnt <= 8; cnt++) {
/* 341 */       dl = createDistributionList(String.format("normaldl%03d@cdgcache.test", new Object[] { Integer.valueOf(cnt) }));
/* 342 */       this.groups.put(dl.getId(), dl);
/* 343 */       dl.addMembers((String[])staticMembers.toArray(new String[staticMembers.size()]));
/* 344 */       for (String mem : staticMembers)
/* 345 */         ZimbraLog.test.info("ZZZ Static Distribution List %s has member acct=%s", new Object[] { dl.getName(), mem });
/*     */     }
/*     */     Group grp;
/* 348 */     for (int cnt = 1; cnt <= 8; cnt++) {
/* 349 */       grp = createDynamicGroup(String.format("dynamicdl%03d@cdgcache.test", new Object[] { Integer.valueOf(cnt) }));
/* 350 */       this.groups.put(grp.getId(), grp);
/* 351 */       this.ldapProv.addGroupMembers(grp, (String[])dynamicMembers.toArray(new String[dynamicMembers.size()]));
/* 352 */       for (String mem : dynamicMembers) {
/* 353 */         ZimbraLog.test.info("ZZZ Dynamic Group %s has member acct=%s", new Object[] { grp.getName(), mem });
/*     */       }
/*     */     }
/* 356 */     String groupName = String.format("cosdl%03d@cdgcache.test", new Object[] { Integer.valueOf(1) });
/*     */     
/*     */ 
/*     */ 
/* 360 */     this.ldapProv.grantRight("domain", com.zimbra.soap.type.TargetBy.name, this.domain.getName(), "grp", com.zimbra.soap.admin.type.GranteeSelector.GranteeBy.name, groupName, null, "createDistList", null);
/*     */     
/*     */ 
/* 363 */     ZimbraLog.test.info("ZZZ Granted %s to Group %s for dom=%s", new Object[] { "createDistList", groupName, this.domain.getName() });
/*     */     
/*     */ 
/*     */ 
/* 367 */     groupName = String.format("normaldl%03d@cdgcache.test", new Object[] { Integer.valueOf(1) });
/* 368 */     this.ldapProv.grantRight("domain", com.zimbra.soap.type.TargetBy.name, this.domain1.getName(), "grp", com.zimbra.soap.admin.type.GranteeSelector.GranteeBy.name, groupName, null, "createDistList", null);
/*     */     
/*     */ 
/* 371 */     ZimbraLog.test.info("ZZZ Granted %s to Group %s for dom=%s", new Object[] { "createDistList", groupName, this.domain.getName() });
/* 372 */     this.ldapProv.grantRight("domain", com.zimbra.soap.type.TargetBy.name, this.domain.getName(), "grp", com.zimbra.soap.admin.type.GranteeSelector.GranteeBy.name, groupName, null, "sendToDistList", null);
/*     */     
/*     */ 
/* 375 */     ZimbraLog.test.info("ZZZ Granted %s to Group %s for dom=%s", new Object[] { "sendToDistList", groupName, this.domain.getName() });
/*     */     
/*     */ 
/*     */ 
/* 379 */     groupName = String.format("dynamicdl%03d@cdgcache.test", new Object[] { Integer.valueOf(1) });
/* 380 */     this.ldapProv.grantRight("domain", com.zimbra.soap.type.TargetBy.name, this.domain2.getName(), "grp", com.zimbra.soap.admin.type.GranteeSelector.GranteeBy.name, groupName, null, "createDistList", null);
/*     */     
/*     */ 
/* 383 */     ZimbraLog.test.info("ZZZ Granted %s to Group %s for dom=%s", new Object[] { "createDistList", groupName, this.domain.getName() });
/*     */     
/*     */ 
/*     */ 
/* 387 */     groupName = String.format("dynamicdl%03d@cdgcache.test", new Object[] { Integer.valueOf(2) });
/* 388 */     this.ldapProv.grantRight("domain", com.zimbra.soap.type.TargetBy.name, this.domain2.getName(), "grp", com.zimbra.soap.admin.type.GranteeSelector.GranteeBy.name, groupName, null, "sendToDistList", null);
/*     */     
/*     */ 
/* 391 */     ZimbraLog.test.info("ZZZ Granted %s to Group %s for dom=%s", new Object[] { "sendToDistList", groupName, this.domain.getName() });
/*     */   }
/*     */   
/*     */   public void tearDown() throws Exception
/*     */   {
/* 396 */     for (int cnt = 1; cnt <= 8; cnt++) {
/* 397 */       deleteGroupIfExists(String.format("normaldl%03d@cdgcache.test", new Object[] { Integer.valueOf(cnt) }));
/*     */     }
/* 399 */     for (int cnt = 1; cnt <= 8; cnt++) {
/* 400 */       deleteGroupIfExists(String.format("dynamicdl%03d@cdgcache.test", new Object[] { Integer.valueOf(cnt) }));
/*     */     }
/* 402 */     for (int cnt = 1; cnt <= 4; cnt++) {
/* 403 */       deleteGroupIfExists(String.format("cosdl%03d@cdgcache.test", new Object[] { Integer.valueOf(cnt) }));
/*     */     }
/* 405 */     for (int cnt = 1; cnt <= 8; cnt++) {
/* 406 */       TestUtil.deleteAccount(String.format("person%03d@cdgcache.test", new Object[] { Integer.valueOf(cnt) }));
/*     */     }
/* 408 */     for (int cnt = 1; cnt <= 4; cnt++) {
/* 409 */       deleteCosIfExists(String.format("cdgcachecos%03d", new Object[] { Integer.valueOf(cnt) }));
/*     */     }
/* 411 */     if (this.domain != null) {
/* 412 */       this.soapProv.deleteDomain(this.domain.getId());
/* 413 */       this.domain = null;
/*     */     }
/* 415 */     if (this.domain1 != null) {
/* 416 */       this.soapProv.deleteDomain(this.domain1.getId());
/* 417 */       this.domain1 = null;
/*     */     }
/* 419 */     if (this.domain2 != null) {
/* 420 */       this.soapProv.deleteDomain(this.domain2.getId());
/* 421 */       this.domain2 = null;
/*     */     }
/*     */   }
/*     */   
/*     */   public Account createAccountAsMemberOfCOS(String name, String cosName) throws Exception
/*     */   {
/* 427 */     Provisioning prov = Provisioning.getInstance();
/* 428 */     Account acct = prov.get(com.zimbra.common.account.Key.AccountBy.name, name);
/* 429 */     if (acct != null) {
/* 430 */       ZimbraLog.test.warn("createAccountAsMemberOfCOS(%s,%s) - already existed!!!", new Object[] { name, cosName });
/* 431 */       return acct;
/*     */     }
/* 433 */     Map<String, Object> attrs = Maps.newHashMap();
/* 434 */     Cos cos = prov.get(com.zimbra.common.account.Key.CosBy.name, cosName);
/* 435 */     attrs.put("zimbraCOSId", cos.getId());
/* 436 */     acct = prov.createAccount(name, "test123", attrs);
/* 437 */     if (acct == null) {
/* 438 */       ZimbraLog.test.warn("createAccountAsMemberOfCOS(%s,%s) returning null!!!", new Object[] { name, cosName });
/*     */     }
/* 440 */     return acct;
/*     */   }
/*     */   
/*     */   public static Domain createDomain(String name) throws Exception
/*     */   {
/* 445 */     Provisioning prov = Provisioning.getInstance();
/* 446 */     Domain dom = prov.get(com.zimbra.common.account.Key.DomainBy.name, name);
/* 447 */     if (dom != null) {
/* 448 */       ZimbraLog.test.warn("createDomain(%s) - already existed!!!", new Object[] { name });
/* 449 */       return dom;
/*     */     }
/* 451 */     Map<String, Object> attrs = Maps.newHashMap();
/* 452 */     dom = prov.createDomain(name, attrs);
/* 453 */     if (dom == null) {
/* 454 */       ZimbraLog.test.warn("createDomain returning null for '%s'", new Object[] { name });
/*     */     }
/* 456 */     return dom;
/*     */   }
/*     */   
/*     */   public static Cos createCos(String name) throws Exception
/*     */   {
/* 461 */     Provisioning prov = Provisioning.getInstance();
/* 462 */     Cos cos = prov.get(com.zimbra.common.account.Key.CosBy.name, name);
/* 463 */     if (cos != null) {
/* 464 */       ZimbraLog.test.warn("createCos(%s) - already existed!!!", new Object[] { name });
/* 465 */       return cos;
/*     */     }
/* 467 */     cos = prov.createCos(name, null);
/* 468 */     if (cos == null) {
/* 469 */       ZimbraLog.test.warn("createCos returning null for '%s'", new Object[] { name });
/*     */     }
/* 471 */     return cos;
/*     */   }
/*     */   
/*     */   public static Group createDynamicGroup(String name) throws Exception
/*     */   {
/* 476 */     Provisioning prov = Provisioning.getInstance();
/* 477 */     Group group = prov.getGroup(com.zimbra.common.account.Key.DistributionListBy.name, name, true);
/* 478 */     if (group != null) {
/* 479 */       ZimbraLog.test.warn("createDynamicGroup(%s) - already existed!!!", new Object[] { name });
/* 480 */       return group;
/*     */     }
/* 482 */     Map<String, Object> attrs = Maps.newHashMap();
/* 483 */     group = prov.createGroup(name, attrs, true);
/* 484 */     if (group == null) {
/* 485 */       ZimbraLog.test.warn("createDynamicGroup returning null for '%s'", new Object[] { name });
/*     */     }
/* 487 */     return group;
/*     */   }
/*     */   
/*     */   public static Group createCustomDynamicGroupWhoseMembersShareCOS(String name, String cosName) throws Exception
/*     */   {
/* 492 */     Provisioning prov = Provisioning.getInstance();
/* 493 */     String dName = name.substring(0, name.indexOf('@') - 1);
/* 494 */     Group group = prov.getGroup(com.zimbra.common.account.Key.DistributionListBy.name, name, true);
/* 495 */     if (group != null) {
/* 496 */       ZimbraLog.test.warn("createCustomDynamicGroupWhoseMembersShareCOS(%s) - already existed!!!", new Object[] { name });
/* 497 */       return group;
/*     */     }
/* 499 */     Map<String, Object> attrs = Maps.newHashMap();
/* 500 */     Cos cos = prov.get(com.zimbra.common.account.Key.CosBy.name, cosName);
/* 501 */     attrs.put("memberURL", String.format("ldap:///??sub?(&(objectClass=zimbraAccount)(zimbraCOSId=%s)(zimbraAccountStatus=active))", new Object[] { cos.getId() }));
/*     */     
/*     */ 
/*     */ 
/* 505 */     attrs.put("zimbraIsACLGroup", "TRUE");
/* 506 */     attrs.put("zimbraMailStatus", "enabled");
/* 507 */     attrs.put("displayName", dName);
/* 508 */     group = prov.createGroup(name, attrs, true);
/* 509 */     if (group == null) {
/* 510 */       ZimbraLog.test.debug("ensureCustomDynamicGroupExists returning null for '%s'", new Object[] { name });
/*     */     }
/* 512 */     return group;
/*     */   }
/*     */   
/*     */   public static DistributionList createDistributionList(String name) throws Exception
/*     */   {
/* 517 */     Provisioning prov = Provisioning.getInstance();
/* 518 */     DistributionList dl = prov.get(com.zimbra.common.account.Key.DistributionListBy.name, name);
/* 519 */     if (dl != null) {
/* 520 */       ZimbraLog.test.warn("createDistributionList(%s) - already existed!!!", new Object[] { name });
/* 521 */       return dl;
/*     */     }
/* 523 */     Map<String, Object> attrs = Maps.newHashMap();
/* 524 */     dl = prov.createDistributionList(name, attrs);
/* 525 */     if (dl == null) {
/* 526 */       ZimbraLog.test.debug("createDistributionList returning null for '%s'", new Object[] { name });
/*     */     }
/* 528 */     return dl;
/*     */   }
/*     */   
/*     */   public static void deleteGroupIfExists(String name) {
/*     */     try {
/* 533 */       Provisioning prov = Provisioning.getInstance();
/* 534 */       Group group = prov.getGroup(com.zimbra.common.account.Key.DistributionListBy.name, name, true);
/* 535 */       if (group != null) {
/* 536 */         prov.deleteGroup(group.getId());
/*     */       }
/*     */     } catch (Exception ex) {
/* 539 */       ZimbraLog.test.error("Problem deleting group " + name, ex);
/*     */     }
/*     */   }
/*     */   
/*     */   public static void deleteCosIfExists(String name) {
/*     */     try {
/* 545 */       Provisioning prov = Provisioning.getInstance();
/* 546 */       Cos res = prov.get(com.zimbra.common.account.Key.CosBy.name, name);
/* 547 */       if (res != null) {
/* 548 */         prov.deleteCos(res.getId());
/*     */       }
/*     */     } catch (Exception ex) {
/* 551 */       ZimbraLog.test.error("Problem deleting Cos " + name, ex);
/*     */     }
/*     */   }
/*     */   
/*     */   public static void main(String[] args)
/*     */     throws Exception
/*     */   {
/*     */     
/*     */     try
/*     */     {
/* 561 */       TestUtil.runTest(TestCustomDynamicGroupCache.class);
/*     */     } catch (Exception e) {
/* 563 */       System.out.println(e.getMessage());
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestCustomDynamicGroupCache.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */